/* coded by e1r0nd 09.03.12 */
/* Placed in public domain	*/

function make_VK_login() {
	var baseURL = window.location.protocol + '//' + window.location.hostname + '/';

	VK.init({
		apiId: 2842362
	});

	VK.Auth.getLoginStatus(function(response) {
		if (response.session) {
				uid = response.session.mid;
				VK.Api.call('getProfiles', {'uids':response.session.mid}, function(response){
						$("#vk_login").html('\
	<table cellspacing="0" cellpadding="0" style="cursor: pointer; border: 0px; font-family: tahoma, arial, verdana, sans-serif, Lucida Sans; font-size: 10px;">\
	<tbody><tr style="vertical-align: middle"><td>\
	<div style="border: 1px solid #3b6798;border-radius: 2px 0px 0px 2px;-moz-border-radius: 2px 0px 0px 2px;-webkit-border-radius: 2px 0px 0px 2px;">\
	<div style="border-width: 1px; border-style: solid; border-right: 1px solid rgb(92, 130, 171); border-color: rgb(126, 156, 188) rgb(92, 130, 171) rgb(92, 130, 171); -moz-border-top-colors: none; -moz-border-right-colors: none; -moz-border-bottom-colors: none; -moz-border-left-colors: none; -moz-border-image: none; background-color: rgb(109, 141, 177); color: rgb(255, 255, 255); text-shadow: 0px 1px rgb(69, 104, 142); height: 15px; padding: 2px 4px 0px 6px; line-height: 13px;">\
	Выйти\
	</div></div></td><td>\
	<div style="background: url(http://vk.com/images/btns.png) 0px -42px no-repeat; width: 21px; height: 21px">\
	</div></td><td>\
	<div style="border: 1px solid rgb(59, 103, 152); border-radius: 0px 2px 2px 0px; background-position: 0px -42px;">\
	<div style="border-width: 1px; border-style: solid; border-right: 1px solid rgb(92, 130, 171); border-color: rgb(126, 156, 188) rgb(92, 130, 171) rgb(92, 130, 171); -moz-border-top-colors: none; -moz-border-right-colors: none; -moz-border-bottom-colors: none; -moz-border-left-colors: none; -moz-border-image: none; background-color: rgb(109, 141, 177); color: rgb(255, 255, 255); text-shadow: 0px 1px rgb(69, 104, 142); height: 15px; padding: 2px 6px 0px 4px; line-height: 13px;">\
	'+response.response[0].first_name+' '+response.response[0].last_name+'\
	</div></div></td></tr></tbody></table>')
						.click(function(){VK.Auth.logout(reloadPage);});
				});
		} else {
			VK.UI.button('vk_login');
			uid = 0;
			$('#vk_login').click(function(){
				VK.Auth.login(
					reloadPage,
					VK.access.FRIENDS | VK.access.WIKI
				);
			});
		}
	});

	function reloadPage() {
		window.location = baseURL;
	}
}